package com.chisheng.caa.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.chisheng.caa.mapper.CourseNatureMapper;
import com.chisheng.caa.mapper.CourseTypeMapper;
import com.chisheng.caa.pojo.dto.CourseNatureDTO;
import com.chisheng.caa.pojo.entity.CourseNature;
import com.chisheng.caa.pojo.entity.CourseType;
import com.chisheng.caa.service.CourseNatureService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class CourseNatureServiceImpl implements CourseNatureService {

    @Resource
    private CourseNatureMapper courseNatureMapper;

    @Resource
    private CourseTypeMapper courseTypeMapper;

    @Override
    public List<CourseNatureDTO> getCourseNatureList() {
        Map<String, String> courseTypeMap = courseTypeMapper
                .selectList(null).stream()
                .collect(Collectors.toMap(CourseType::getTypeId, CourseType::getTypeName));
        
        return courseNatureMapper.selectList(null).stream()
                .map(source -> {
                    CourseNatureDTO dest = new CourseNatureDTO();
                    BeanUtil.copyProperties(source, dest);
                    dest.setTypeName(courseTypeMap.get(source.getTypeId()));
                    return dest;
                }).collect(Collectors.toList());
    }

    @Override
    public List<String> getCourseNatureNameList() {
        return courseNatureMapper.selectList(null)
                .stream()
                .map(CourseNature::getNatureName)
                .collect(Collectors.toList());
    }

}
